import { _decorator, Component, instantiate, Node } from 'cc';
import { BaseComponent } from '../../../Manager/UIManager/BaseComponent';
import { GAME_PREFAB } from '../../../Data/GlobalData';
import { SingleGun } from './SingleGun';
const { ccclass, property } = _decorator;

@ccclass('GunLoad')
export class GunLoad extends BaseComponent {

    //炮台层
    @property(Node)
    private GunNode: Node = null;

    /**
     * 清除所有炮台
     */
    public ClearAllGun() {
        for (let gun of this.GunNode.children) {
            if (gun.getComponent(SingleGun).GunLoad.active) {
                gun.getComponent(SingleGun).Init();
            }

            this.GunNode.children[0].getComponent(SingleGun).IamLock();
            this.GunNode.children[this.GunNode.children.length - 1].getComponent(SingleGun).IamLock();
        }
    }

    /**
     * 返回炮台是否有位置
     */
    public ReturnCanAddGun(): boolean {

        for (let gun of this.GunNode.children) {
            if (!gun.getComponent(SingleGun).GunLoad.active && !gun.getComponent(SingleGun).LockNode.active) {
                return true;
            }
        }

        return false;
    }

    /**
     * 添加炮台
     */
    public AddGun(_gunindx: number, _guncount: number) {
        for (let gun of this.GunNode.children) {
            if (!gun.getComponent(SingleGun).GunLoad.active && !gun.getComponent(SingleGun).LockNode.active) {
                gun.getComponent(SingleGun).UpdateGunStyle(_gunindx, _guncount);
                break;
            }
        }
    }


}


